﻿Imports System.Collections.Generic
Imports System.Data
Imports System.Data.SqlClient


''' <summary>
''' Clase de la capa de acceso a datos DAL que implementa el patrón Table Data Gateway para el manejo de la entidad Postulante
''' </summary>
''' <remarks></remarks>
Public Class TDGPostulante

    Private Shared m_Instance As TDGPostulante = Nothing


    Public Function Insert(conn As SqlConnection, _
                        TDOC_Codigo As String, _
                        Postu_NroDoc As String, _
                        Postu_NombreAp As String, _
                        Postu_FNac As Date, _
                        Postu_Nacionalidad As String, _
                        Postu_Telefono As String, _
                        Postu_Mail As String, _
                        Postu_Estudios As String, _
                        Postu_Experiencia As String, _
                        Postu_Observaciones As String, _
                        DVH As Int32) As Int16
        Dim command As New SqlCommand
        Dim iRowsAffected As Int16


        command.Connection = conn
        command.CommandType = CommandType.StoredProcedure

        command.CommandText = "dbo.addPostulante"
        command.Parameters.AddWithValue("@TDOC_Codigo", TDOC_Codigo)
        command.Parameters.AddWithValue("@Postu_NroDoc", Postu_NroDoc)
        command.Parameters.AddWithValue("@Postu_NombreAp", Postu_NombreAp)
        command.Parameters.AddWithValue("@Postu_FNac", Postu_FNac)
        command.Parameters.AddWithValue("@Postu_Nacionalidad", Postu_Nacionalidad)
        command.Parameters.AddWithValue("@Postu_Telefono", Postu_Telefono)
        command.Parameters.AddWithValue("@Postu_Mail", Postu_Mail)
        command.Parameters.AddWithValue("@Postu_Estudios", Postu_Estudios)
        command.Parameters.AddWithValue("@Postu_Experiencia", Postu_Experiencia)
        command.Parameters.AddWithValue("@Postu_Observaciones", Postu_Observaciones)
        command.Parameters.AddWithValue("@DVH", DVH)


        iRowsAffected = command.ExecuteNonQuery()


        Return iRowsAffected

    End Function

    Public Function Update(conn As SqlConnection, _
                        TDOC_Codigo As String, _
                        Postu_NroDoc As String, _
                        Postu_NombreAp As String, _
                        Postu_FNac As Date, _
                        Postu_Nacionalidad As String, _
                        Postu_Telefono As String, _
                        Postu_Mail As String, _
                        Postu_Estudios As String, _
                        Postu_Experiencia As String, _
                        Postu_Observaciones As String, _
                        DVH As Int32) As Int16
        Dim command As New SqlCommand
        Dim iRowsAffected As Int16


        command.Connection = conn
        command.CommandType = CommandType.StoredProcedure

        command.CommandText = "dbo.updPostulante"
        command.Parameters.AddWithValue("@TDOC_Codigo", TDOC_Codigo)
        command.Parameters.AddWithValue("@Postu_NroDoc", Postu_NroDoc)
        command.Parameters.AddWithValue("@Postu_NombreAp", Postu_NombreAp)
        command.Parameters.AddWithValue("@Postu_FNac", Postu_FNac)
        command.Parameters.AddWithValue("@Postu_Nacionalidad", Postu_Nacionalidad)
        command.Parameters.AddWithValue("@Postu_Telefono", Postu_Telefono)
        command.Parameters.AddWithValue("@Postu_Mail", Postu_Mail)
        command.Parameters.AddWithValue("@Postu_Estudios", Postu_Estudios)
        command.Parameters.AddWithValue("@Postu_Experiencia", Postu_Experiencia)
        command.Parameters.AddWithValue("@Postu_Observaciones", Postu_Observaciones)
        command.Parameters.AddWithValue("@DVH", DVH)


        iRowsAffected = command.ExecuteNonQuery()

        Return iRowsAffected

    End Function

    Public Function Delete(conn As SqlConnection, TDOC_Codigo As String, Postu_NroDoc As String) As Int16
        Dim command As New SqlCommand
        Dim iRowsAffected As Int16

        command.Connection = conn
        command.CommandType = CommandType.StoredProcedure
        command.CommandText = "dbo.delPostulante"
        command.Parameters.AddWithValue("@TDOC_Codigo", TDOC_Codigo)
        command.Parameters.AddWithValue("@Postu_NroDoc", Postu_NroDoc)

        iRowsAffected = command.ExecuteNonQuery()

        Return iRowsAffected

    End Function

    Public Function Find(conn As SqlConnection, TDOC_Codigo As String, Postu_NroDoc As String) As SqlDataReader
        Dim command As New SqlCommand
        Dim dr As SqlDataReader


        command.Connection = conn
        command.CommandType = CommandType.StoredProcedure

        command.CommandText = "dbo.getPostulante"
        command.Parameters.AddWithValue("@TDOC_Codigo", TDOC_Codigo)
        command.Parameters.AddWithValue("@Postu_NroDoc", Postu_NroDoc)


        dr = command.ExecuteReader()

        Return dr

    End Function

    Public Function FindAll(conn As SqlConnection) As SqlDataReader
        Dim command As New SqlCommand
        Dim dr As SqlDataReader


        command.Connection = conn
        command.CommandType = CommandType.StoredProcedure

        command.CommandText = "dbo.getPostulante_All"


        dr = command.ExecuteReader()

        Return dr

    End Function

    Public Shared ReadOnly Property Instance()
        Get
            If (m_Instance Is Nothing) Then
                m_Instance = New TDGPostulante()
            End If

            Return m_Instance
        End Get
    End Property

    Private Sub New()

    End Sub

End Class
